package com.earogya.springsecurity.web.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.ModelAttribute;


/**
 * The base Spring controller. Used to provide common functionality to all controllers.
 * 
 * @author Ureka
 */
public class BaseController {
	protected Authentication getAuthentication() {
		return SecurityContextHolder.getContext().getAuthentication();
		}
	
	@ModelAttribute("showUsername")
	public boolean getShowUsername() {
	for (GrantedAuthority authority : getAuthentication().getAuthorities()) {
	if(authority.getAuthority().equals("ROLE_ADMIN")) {
	return true;
	}
	}
	return false;
	}
}
